#pragma once

#include "EventHandler.h"
#include "SOCK_Acceptor.h"
#include "Reactor.h"

namespace Network
{
	template <class SERVICE_HANDLER> class Acceptor : public EventHandler
	{
	public:
		Acceptor<SERVICE_HANDLER>(INET_Addr &addr, Reactor *reactor ):acceptor(addr), reactor(reactor)
		{
			this->reactor = reactor;
			reactor->RegisterHandler(this, ACCEPT_EVENT);
		};
	
		~Acceptor<SERVICE_HANDLER>(void)
		{
			this->reactor->RemoveHandler( this, ACCEPT_EVENT );
		};
	
		virtual void HandleEvent(HANDLE handle, EventType et )
		{
			if( et == ACCEPT_EVENT )
			{
				SOCK_Stream clientConnection( handle );
				acceptor.accept( clientConnection );
				SERVICE_HANDLER* leh = new SERVICE_HANDLER( clientConnection, reactor );
			}
		};

		virtual HANDLE GetHandle(void)
		{
			return acceptor.GetHandle();
		};
	private:
		SOCK_Acceptor acceptor;
		Reactor *reactor;
	};
}